package com.musicserver.controller;

import com.musicserver.common.R;
import com.musicserver.model.request.SongRequest;
import com.musicserver.service.SongService;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
public class SongController {
    @Autowired
    private SongService songService;

    // 返回所有歌曲
    @GetMapping("/song")
    public R allSong() {
        return songService.allSong();
    }

    // 获取指定歌手的指定歌曲
    @GetMapping("/song/singer/detail")
    public R singerDetail(@RequestParam int singerId){
        return songService.songOfSingerId(singerId);
    }

    // 获取指定歌单中的歌曲
    @GetMapping("/song/songList/{songListId}")
    public R songOfSongList(@PathVariable int songListId){
        return songService.songOfSongListId(songListId);
    }

    // 添加歌曲
    @PostMapping("/song/add")
    public R addSong(SongRequest addSongRequest,
                     @RequestParam("file") MultipartFile mpfile,
                     HttpServletRequest request) {
        return songService.addSong(addSongRequest, mpfile);
    }

    // 更新歌曲信息
    @PostMapping("/song/update")
    public R updateSongMsg(@RequestBody SongRequest updateSongRequest) {
        return songService.updateSongMsg(updateSongRequest);
    }

    // 删除歌曲
    @DeleteMapping("/song/delete")
    public R deleteSong(@RequestParam int id) {
        return songService.deleteSong(id);
    }

    @DeleteMapping("/song/deleteIds")
    public R deleteSongs(@RequestParam String[] id) {
        return songService.deleteSongs(id);
    }

    // 返回歌名中包含指定关键字的歌曲
    @GetMapping("/song/songName/detail")
    public R songOfSingerName(@RequestParam String name) {
        return songService.songOfSongName(name);
    }
}
